// -*- coding: utf-8 -*- 
/**
 * Project: AlgorithmsLearn
 *
 * @author: yanking
 * Create time: 2022-03-16 16:48
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.LeetCodeT.ArraysTrain;

import java.util.HashMap;

public class ContainsDuplicate {
    /**
     * 判断数组中是否存在重复元素
     *
     * @param nums
     * @return
     */
    public boolean containsDuplicate(int[] nums) {
        int n = nums.length;
        HashMap<Integer, Boolean> data = new HashMap<>();
        for (int i = 0; i < n; i++) {
            Boolean orDefault = data.getOrDefault(nums[i], false);
            if (orDefault) {
                return true;
            } else {
                data.put(nums[i], true);
            }
        }
        return false;
    }
}
